package com.fengye.algorithms.leecode;

import com.fengye.algorithms.leecode.common.TreeNode;

/**
 * @Author fengye
 * @Date 2023/4/17 4:36
 **/
public class MaximumdepthOfBinaryTree104 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(3);

        System.out.println(new MaximumdepthOfBinaryTree104().maxDepth(root));
    }

    public int maxDepth(TreeNode root) {
        if (root==null) {
            return 0;
        }
        int i = maxDepth(root.left);
        int i1 = maxDepth(root.right);
        return Math.max(i,i1)+1;

    }

    public int maxDepth2(TreeNode root) {
        if(root == null) {
            return 0;
        }

        return dps(root);
    }

    public int dps(TreeNode node) {
        if(node == null) {
            return 0;
        }

        int c = 1;
        if(node.left != null && node.right != null) {
            int c1 = dps(node.left);
            int c2 = dps(node.right);
            c += Math.max(c1, c2);
        } else if(node.left != null && node.right == null) {
            c += dps(node.left);
        } else if (node.right != null && node.left == null) {
            c += dps(node.right);
        }

        return c;
    }
}
